//
//  FindCarTableViewCell.m
//  CarTown
//
//  Created by xionghao on 15/8/29.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "FindCarTableViewCell.h"
#define kTableTopBorderWidth 8;

@implementation FindCarTableViewCell

+(instancetype)CellWithTableView:(UITableView *)tableView{
    static NSString *cellid=@"findcar";
    FindCarTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid];
    
    if (cell==nil) {
        
        [tableView registerNib:[UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil] forCellReuseIdentifier:cellid];
        cell=[tableView dequeueReusableCellWithIdentifier:cellid];

    }
    
    return cell;
}
- (IBAction)buttonclick:(UIButton *)sender {
   
    if ([_delegate respondsToSelector:@selector(buttonclickWith:WithIndex:)]) {
        [_delegate buttonclickWith:self WithIndex:sender.tag];
    }


}
-(void)setFrame:(CGRect)frame{
    frame.origin.y += kTableTopBorderWidth;
    frame.size.height -= kTableTopBorderWidth;
    
    [super setFrame:frame];
    
}



-(void)setMode:(FindCarMode *)mode{
    _mode=mode;
    self.title.text=_mode.car_name;
    self.selectedbtn.selected=_mode.ischecked;
    NSString *subtitle=@"";
    if ([_mode.car_outside_color isEqualToString:@"不限"]&&[_mode.car_inside_color isEqualToString:@"不限"]) {
        subtitle=@"不限";
    }else{
        subtitle=[NSString stringWithFormat:@"%@/%@",_mode.car_outside_color,_mode.car_inside_color];}
    if (![_mode.deal_address isEqualToString:@""]&&_mode.deal_address) {
        subtitle=[NSString stringWithFormat:@"%@|%@",subtitle,_mode.deal_address];
    }
    if (![_mode.valid_time isEqualToString:@"0"]) {
        subtitle=[NSString stringWithFormat:@"%@|求购有效期:%@天",subtitle,_mode.valid_time];
    }
    
    self.subtitle.text=subtitle;
    self.namelable.text=_mode.sale_name;
    self.time.text=[NSDate dateStrFromTimeStr:_mode.addtime];
    if ([_mode.sale_type isEqualToString:@"个人商铺"]) {
        self.typeicon.image=[UIImage imageNamed:@"ico_p"];
    }else if ([_mode.sale_type isEqualToString:@"资源公司"]) {
        self.typeicon.image=[UIImage imageNamed:@"ico_z"];
    }else if ([_mode.sale_type isEqualToString:@"综合销售店"]) {
        self.typeicon.image=[UIImage imageNamed:@"ico_zonghe"];
    }else if ([_mode.sale_type isEqualToString:@"4S店"]) {
        self.typeicon.image=[UIImage imageNamed:@"ico_4s"];
    }else if ([_mode.sale_type isEqualToString:@"港口批发商"]) {
        self.typeicon.image=[UIImage imageNamed:@"ico_hk"];
    }
    switch ([_mode.sale_type integerValue]) {
        case GANGKOU:
            
            self.typeicon.image=[UIImage imageNamed:@"ico_hk"];
            break;
        case FOURS:
            
            self.typeicon.image=[UIImage imageNamed:@"ico_4s"];
            break;
        case PERSONAL:
           self.typeicon.image=[UIImage imageNamed:@"ico_p"];
            
            break;
        case ZIYUAN:
           self.typeicon.image=[UIImage imageNamed:@"ico_z"];
            break;
        case ZONGHE:
            self.typeicon.image=[UIImage imageNamed:@"ico_zonghe"];
            break;
        default:
            break;
    }

    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
